import numpy as np
import matplotlib.pyplot as plt

# Define the grid
n = 6  # Number of grid points
h = 1 / n  # Step size
x = np.linspace(0, 1, n + 1)  # Grid points

# Define the Fourier mode
def fourier_mode(x, k):
    return np.sin(k * np.pi * x)

# Original mode (k = 9)
k_original = 9
y_original = fourier_mode(x, k_original)

# Aliased mode (k = 3)
k_aliased = 3
y_aliased = fourier_mode(x, k_aliased)

# Plot the modes
plt.figure(figsize=(10, 6))
plt.plot(x, y_original, 'bo-', label=f'Original mode: $k = {k_original}$')
plt.plot(x, y_aliased, 'ro-', label=f'Aliased mode: $k = {k_aliased}$')

plt.title('Fourier Modes for $n = 6$')
plt.xlabel('$x$')
plt.ylabel('$w_k(x)$')
plt.legend()
plt.grid(True)
plt.savefig('9.14.png', dpi=300, bbox_inches='tight')  # Save the plot for LaTeX
plt.show()